package com.jie.files.service.impl;

import com.jie.files.dao.UserDao;
import com.jie.files.entity.User;
import com.jie.files.service.UserService;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Jeson
 * @description
 * @create 2021/10/4
 * @since 1.0.0
 */
@Service
@Transactional
public class UserServiceImpl  implements UserService{

    @Autowired
    private UserDao userDao;

    @Override
    public User login(User user) {
        return userDao.login(user);
    }

    @Override
    public User findUserByUsernmae(String principal) {
        User userByUsername = userDao.findUserByUsername(principal);
        return userByUsername;
    }

    @Override
    public void register(User user) {
        String salt="@#44!$";
        Md5Hash md5Hash=new Md5Hash(user.getPassword(),salt,1024);
        user.setPassword(md5Hash.toHex());
        userDao.rehister(user);
    }
}